package com.alex.server.controller;

import com.alex.server.pojo.Admin;
import com.alex.server.pojo.ChatMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
//@Controller
//public class WsController {
//@Resource
//    private SimpMessagingTemplate simpMessagingTemplate;
//
//    @MessageMapping("/ws/chat")
//    public void handleMsg(Authentication authentication, ChatMsg chatMsg){
//        Admin admin = (Admin) authentication.getPrincipal();
//        chatMsg.setFrom(admin.getUsername());
//        chatMsg.setFromNickName(admin.getName());
//        chatMsg.setLocalDateTime(LocalDateTime.now());
//        simpMessagingTemplate.convertAndSendToUser(chatMsg.getTo(),"/queue/chat",chatMsg);
//    }
//}
